home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / spar372.zip / SPAR_DEV.H < prev    next >
C/C++ Source or Header  |  1994-01-18  |  8KB  |  244 lines

  1. /*
  2. ** $Source: dh1:network/parnet/Sana2/Sources/Spar_device.h,v $
  3. ** $State: Exp $
  4. ** $Revision: 37.2 $
  5. ** $Date: 93/12/17 22:13:33 $
  6. ** $Author: S.A.Pechler $
  7. **
  8. ** SANA-II Example device driver C include file
  9. **
  10. ** Based on the Amiga SANA-II Example SLIP device driver code by bj and the
  11. ** rhslip.device by rhialto@mbfys.kun.nl (Olaf Seibert)
  12. **
  13. ** Portions (C) Copyright 1992 Commodore-Amiga, Inc.
  14. */
  15.  
  16. #include <exec/types.h>
  17. #include <exec/devices.h>
  18. #include <exec/ports.h>
  19. #include <exec/semaphores.h>
  20. #include <exec/memory.h>
  21. #include <dos.h>
  22. #include <devices/sana2.h>
  23. #include <devices/parnet.h>
  24.  
  25. /*
  26. ** Stacksize and Priority of the Unit Process
  27. */
  28. #define SPAR_STACKSIZE 4000
  29. #define SPAR_PRI 5
  30.  
  31. /*
  32. ** Maximum Transmission Unit
  33. */
  34. #define SPAR_MTU 8192+256
  35.  
  36. /* Hmm, I still need to determine the *real* PARnet bps
  37.  */
  38. #define SPAR_SPEED 28672
  39.  
  40. /* Use PARnet port 1024 for TCP/IP communications
  41.  * WARNING: don't change this value when you want to stay compatible 
  42.  * with the PARnet-PC packet driver.
  43.  */
  44. #define SPAR_PORT 1024
  45.  
  46. /* Length of an IP address in bytes. */
  47. #define IADDR_LEN 4
  48.  
  49. /* Length of a Spar address in bytes. */
  50. #define SADDR_LEN 1
  51.  
  52. /* Length of an Ethernet address in bytes. */
  53. #define EADDR_LEN 6
  54.  
  55. /*
  56. ** Spar frame header structure.
  57. */
  58. struct Spar_Hdr
  59.        {
  60.          UBYTE SDstAddr; /* Destination hardware address */
  61.          UBYTE SSrcAddr; /* Source hardware address */
  62.          UWORD SFrmType; /* Frame type (Using Ethernet frame type) */
  63.        };
  64. /*
  65. ** Length of a Spar frame header in bytes.
  66. */
  67. #define SHDR_LEN sizeof(struct Spar_Hdr)
  68.  
  69. /*
  70. ** Max # of Units allowed
  71. */
  72. #define SD_MAXUNITS 8
  73.  
  74. /*
  75. ** Message passed to the Unit Process at
  76. ** startup time.
  77. */
  78. struct StartupMessage
  79. {
  80.   struct Message  Msg;
  81.   struct Unit     *Unit;
  82.   struct Device   *Device;
  83. };
  84.  
  85. /*
  86. ** Device Data Structure
  87. */
  88. struct SPARDevice
  89. {
  90.     struct Library          sd_Device;
  91.     UBYTE                   sd_Flags;
  92.     UBYTE                   sd_Pad1;
  93.     struct Library         *sd_SysBase;
  94.     struct Library         *sd_DOSBase;
  95.     ULONG                   sd_DosTag[10];
  96.     BPTR                    sd_SegList;
  97.     struct Unit            *sd_Units[SD_MAXUNITS];
  98.     struct SignalSemaphore  sd_Lock;
  99.     struct StartupMessage   sd_Startup;
  100. };
  101.  
  102. /*
  103. ** Typedef's for the SANA-II callback functions.
  104. ** Rhialto: It would be nice to specify the registers explicitly,
  105. ** instead of hoping the compiler options include ARGS=REGS, and that
  106. ** the compiler selected registers would match the requirements.
  107. */
  108. #ifdef __SASC
  109. # define ASM          __asm
  110. # define REG(x)       register __ ## x
  111. #else
  112. # error Please define ASM and REG for your compiler
  113. #endif
  114.  
  115. typedef BOOL (*ASM SANA2_CFB)(REG(a0) APTR to, REG(a1) APTR from, REG(d0) LONG length);
  116. typedef BOOL (*ASM SANA2_CTB)(REG(a0) APTR to, REG(a1) APTR from, REG(d0) LONG length);
  117.  
  118. struct BufferManagement
  119. {
  120.    struct MinNode   bm_Node;
  121.    SANA2_CFB        bm_CopyFromBuffer;
  122.    SANA2_CTB        bm_CopyToBuffer;
  123. };
  124.  
  125. struct SuperS2PTStats
  126. {
  127.    struct MinNode               ss_Node;
  128.    ULONG                        ss_PType;
  129.    struct Sana2PacketTypeStats  ss_Stats;
  130. };
  131.  
  132. /*
  133. ** Unit Data Structure
  134. */
  135. struct SPARDevUnit
  136. {
  137.     struct Unit              sdu_Unit;            /* Standard Unit Structure */
  138.     UBYTE                    sdu_UnitNum;         /* Unit number */
  139.     UBYTE                    sdu_StAddr;          /* Our current address */
  140.     struct Device           *sdu_Device;          /* Pointer to our device node */
  141.     UBYTE                    sdu_HwAddr;          /* Our "hardware" address (Rhialto)*/
  142.     UBYTE                    sdu_DestAddr;        /* Destination address when point-to-point */
  143.     ULONG                    sdu_ParUnitNum;      /* PARnet driver unit number */
  144.     BOOL                     sdu_NoMore;          /* Flag: work to do for Unit process */
  145.     ULONG                    sdu_State;           /* Various state information */
  146.     struct IOParReq         *sdu_ParRx;           /* PARnet IORequest for CMD_READ's */
  147.     struct IOParReq         *sdu_ParTx;           /* PARnet IORequest for CMD_WRITE's */
  148.     struct MsgPort          *sdu_RxPort;          /* PARnet CMD_READ IORequest reply port */
  149.     struct MsgPort          *sdu_TxPort;          /* PARnet CMD_WRITE IORequest reply port */
  150.     UBYTE                   *sdu_RxBuff;          /* Buffer for holding packets */
  151.     UBYTE                   *sdu_TxBuff;          /* Temporary buffer for hold outgoing packets */
  152.     struct Process          *sdu_Proc;            /* NB: This points to the Task, not the MsgPort */
  153.     struct SignalSemaphore   sdu_ListLock;        /* A Semaphore for access to all of our queues. */
  154.     struct MinList           sdu_Rx;              /* Pending CMD_READ's */
  155.     struct MinList           sdu_RxOrph;          /* Pending CMD_READORPHAN's */
  156.     struct MinList           sdu_Tx;              /* Pending CMD_WRITE's */
  157.     struct MinList           sdu_Events;          /* Pending S2_ONEVENT's */
  158.     BOOL                     sdu_TrackP;          /* Flag: a packet to track is present */
  159.     struct MinList           sdu_Track;           /* List of packet types being tracked */
  160.     struct MinList           sdu_BuffMgmt;        /* List of Callback routines */
  161.     struct Sana2DeviceStats  sdu_Stats;           /* Global device statistics */
  162.     UBYTE                    sdu_ParDevName[32];  /* Name of the PARnet driver to use */
  163. };
  164.  
  165. /*
  166. ** State bits for sdu_State
  167. */
  168.  
  169. #define SPARUB_ONLINE 0
  170. #define SPARUB_CONFIG 1
  171. #define SPARUB_CONTROL 2
  172. #define SPARUB_DGRAM 3
  173. #define SPARUB_STREAM 4
  174.  
  175. #define SPARUF_ONLINE       (1<<SPARUB_ONLINE)
  176. #define SPARUF_CONFIG       (1<<SPARUB_CONFIG)
  177. #define SPARUF_CONTROL      (1<<SPARUB_CONTROL)
  178. #define SPARUF_DGRAM        (1<<SPARUB_DGRAM)
  179. #define SPARUF_STREAM       (1<<SPARUB_STREAM)
  180.  
  181. /*
  182. ** ARP definitions
  183. ** Spar does not support packet broadcast, therefor it processes ARP
  184. ** requests from the local host internally. 
  185. */
  186.  
  187. /* Spar frame type (using Ethernet frame types) */
  188. #define ETHERTYPE_IP    0x0800          /* IP protocol */
  189. #define ETHERTYPE_ARP   0x0806          /* ARP packet */
  190.  
  191. /* ARP frame packet content for 6 byte ethernet hardware addresses */
  192. struct ARPframePacket
  193.        { UBYTE ar_dstaddr;   /* frame target hardware address (myself) */
  194.          UBYTE ar_srcaddr;   /* frame source hardware address (fake!) */
  195.          UWORD ar_ftype;     /* frame type field (0x0806 = ARP_TYPE) */
  196.          UWORD ar_hrd;       /* hardware type: */
  197. #define  ARPHRD_ETHER    1   /* ethernet hardware address */
  198. #define  ARPHRD_ARCNET   7   /* ARCNET hardware address */
  199.          UWORD ar_pro;       /* protocol type (0x0800 = IP) */
  200.          UBYTE ar_hln;       /* hardware address length (6 for Ethernet) */
  201.          UBYTE ar_pln;       /* higher level address length (4 = IP) */
  202.          UWORD ar_op;        /* operation: */
  203. #define  ARPOP_REQUEST   1   /* request to resolve address */
  204. #define  ARPOP_REPLY     2   /* response to previous request */
  205.  
  206. /* These fields are normally variable in size, but Spar only works with
  207.  * six-byte hardware addresses and 4 octet IP addresses. */
  208.          UBYTE ar_sha[6];       /* sender hardware address */
  209.          ULONG ar_spa;          /* sender protocol address */
  210.          UBYTE ar_tha[6];       /* target hardware address */
  211.          ULONG ar_tpa;          /* target protocol address */
  212.        };
  213. /*
  214. ** Device Name
  215. */
  216. #ifdef DEBUG
  217. # define SPARDEVNAME "spardebug.device"
  218. #else
  219. # define SPARDEVNAME "spar.device"
  220. #endif
  221. extern char SPARName[];
  222.  
  223. /*
  224. ** Compiler Magic
  225. **
  226. ** (Rhialto) This is terrible!!! That people write code like this!
  227. ** How can you be sure the compiler won't use A6 for a register variable
  228. ** somewhere and make it unusable in the functions that it calls?
  229. ** (in fact, SAS/C 6.2 does something that, in ReadConfig..., when it
  230. ** first calls an Exec function and then a DOS function)
  231. **
  232. */
  233.  
  234. #ifdef notdef
  235. /* SPARBase must be in register a6 */
  236. # define SPARBase ((struct SPARDevice *)__builtin_getreg(14))      /* Avoid the pre-processor problem */
  237. #else
  238. #define SPARBase    ExtDeviceBase
  239. #endif
  240.  
  241. /* pointer to exec (initialized in DevInit(), see spar_device.asm) */
  242. #define SysBase      (SPARBase->sd_SysBase)
  243. #define DOSBase      (SPARBase->sd_DOSBase)
  244.